<?php

namespace app\common\model\question;

use app\common\model\Model;
use traits\model\SoftDelete;

class Notice extends Model
{

    use SoftDelete;

    protected $dateFormat = 'Y-m-d H:i:s';

    // 表名
    protected $name = 'question_notice';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'datetime';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'type_text'
    ];

    public function getTypeList()
    {
        return ['1' => __('公告'), '2' => __('通知')];
    }

    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function category()
    {
        return $this->belongsTo(Category::class, 'question_category_id')->setEagerlyType(0);
    }
}
